﻿using Island;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DetailPanel : UIBase {

    Account account;
    RawImage rawImage;

    Button backBtn;
    Button islandBtn;
    Button friendBtn;
    Button chatBtn;

    void Awake()
    {
        rawImage = transform.Find("RawImage").GetComponent<RawImage>();

        backBtn = transform.Find("BackBtn").GetComponent<Button>();
        islandBtn = transform.Find("IslandBtn").GetComponent<Button>();
        friendBtn = transform.Find("FriendBtn").GetComponent<Button>();
        chatBtn = transform.Find("ChatBtn").GetComponent<Button>();

        backBtn.onClick.AddListener(OnBackClick);
        islandBtn.onClick.AddListener(OnIslandClick);
        friendBtn.onClick.AddListener(OnFriendClick);
        chatBtn.onClick.AddListener(OnChatClick);

    }

    private void OnChatClick()
    {
        UIManager.Instance.Open<ChatPanel>();
    }

    private void OnFriendClick()
    {
        PBFriend pb = new PBFriend();
        pb.id = account.id;
        NetworkManager.Instance.Send(Protocol.ReqApplyFriend, pb);

        MessageBox.Show("申请已发送!");
    }

    private void OnIslandClick()
    {
        MessageBox.Show("海岛功能暂未开放!");
    }

    private void OnBackClick()
    {
        UIManager.Instance.Open<ArPanel>();
        UIManager.Instance.Close<DetailPanel>();
    }

    public override void Init(params object[] args)
    {
        account = args[0] as Account;
        Actor actor = Util.CreateActor(account.sex);

        rawImage.gameObject.SetActive(true);
        RenderTool.Instance.AddRenderTex(rawImage,actor.gameObject);
    }

    public override void OnClose(params object[] args) {
        RenderTool.Instance.Close();
    }

}
